package _nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author: huangya
 * @Date: 2020/5/29
 * @Description:
 */
public class NIOTest2 {

    public static void main(String[] args) throws Exception {

        File src = new File("D:\\tool/iToolsSetup_4.2.0.6.exe");
        FileInputStream fis = new FileInputStream(src);
        FileOutputStream fos = new FileOutputStream(new File("D:/iToolsSetup_4.2.0.6.exe"));

        ByteBuffer buffer = ByteBuffer.allocate(1024);

        FileChannel channelin = fis.getChannel();
        FileChannel channelout = fos.getChannel();

        while (channelin.read(buffer) != -1) {
            System.out.println("--");
            buffer.flip();
            channelout.write(buffer);
            buffer.clear();
        }

        fis.close();
        fos.close();
        System.out.println("over");
    }

}
